home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / boekhoud / finan / BADGER finance v1.0 beta 2.exe / xampplite / phpMyAdmin / libraries / tbl_properties_table_info.inc.php < prev    next >
PHP Script  |  2005-12-08  |  4KB  |  101 lines

  1. <?php
  2. /* $Id: tbl_properties_table_info.inc.php,v 1.3 2005/12/08 12:14:34 cybot_tm Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * extracts table properties from create statement
  7.  *
  8.  * @TODO this should be recoded as functions,
  9.  * to avoid messing with global variables
  10.  */
  11.  
  12. /**
  13.  * requirements
  14.  */
  15. require_once('./libraries/common.lib.php');
  16.  
  17. // Check parameters
  18. PMA_checkParameters(array('db', 'table'));
  19.  
  20. /**
  21.  * Defining global variables, in case this script is included by a function.
  22.  * This is necessary because this script can be included by libraries/header.inc.php.
  23.  */
  24. global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
  25.        $table_info_num_rows, $auto_increment;
  26.  
  27. /**
  28.  * Gets table informations
  29.  */
  30. // Seems we need to do this in MySQL 5.0.2,
  31. // otherwise error #1046, no database selected
  32. PMA_DBI_select_db($GLOBALS['db']);
  33.  
  34. // The 'show table' statement works correct since 3.23.03
  35. $table_info_result   = PMA_DBI_query(
  36.     'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
  37.     null, PMA_DBI_QUERY_STORE);
  38.  
  39. // need this test because when we are creating a table, we get 0 rows
  40. // from the SHOW TABLE query
  41. // and we don't want to mess up the $tbl_type coming from the form
  42.  
  43. if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
  44.     $showtable           = PMA_DBI_fetch_assoc($table_info_result);
  45.     PMA_DBI_free_result($table_info_result);
  46.     unset( $table_info_result );
  47.  
  48.     if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
  49.         $showtable['Type'] =& $showtable['Engine'];
  50.     }
  51.     // MySQL < 5.0.13 returns "view", >= 5.0.13 returns "VIEW"
  52.     if ( PMA_MYSQL_INT_VERSION >= 50000 && !isset($showtable['Type'])
  53.       && isset($showtable['Comment'])
  54.       && strtoupper($showtable['Comment']) == 'VIEW' ) {
  55.         $tbl_is_view     = true;
  56.         $tbl_type        = $GLOBALS['strView'];
  57.         $show_comment    = null;
  58.     } else {
  59.         $tbl_is_view     = false;
  60.         $tbl_type        = isset($showtable['Type'])
  61.             ? strtoupper($showtable['Type'])
  62.             : '';
  63.         // a new comment could be coming from tbl_properties_operations.php
  64.         // and we want to show it in the header
  65.         if (isset($submitcomment) && isset($comment)) {
  66.             $show_comment = $comment;
  67.         } else {
  68.             $show_comment    = isset($showtable['Comment'])
  69.                 ? $showtable['Comment']
  70.                 : '';
  71.         }
  72.     }
  73.     $tbl_collation       = empty($showtable['Collation'])
  74.         ? ''
  75.         : $showtable['Collation'];
  76.  
  77.     if ( null === $showtable['Rows'] ) {
  78.         $showtable['Rows']   = PMA_countRecords( $GLOBALS['db'],
  79.             $showtable['Name'], true, true );
  80.     }
  81.     $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
  82.     $auto_increment      = isset($showtable['Auto_increment'])
  83.         ? $showtable['Auto_increment']
  84.         : '';
  85.  
  86.     $create_options      = isset($showtable['Create_options'])
  87.         ? explode(' ', $showtable['Create_options'])
  88.         : array();
  89.  
  90.     // export create options by its name as variables into gloabel namespace
  91.     // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
  92.     foreach ( $create_options as $each_create_option ) {
  93.         $each_create_option = explode('=', $each_create_option);
  94.         if ( isset( $each_create_option[1] ) ) {
  95.             $$each_create_option[0]    = $each_create_option[1];
  96.         }
  97.     }
  98.     unset( $create_options, $each_create_option );
  99. } // end if
  100. ?>
  101.